<template>
    <div>
    <van-nav-bar
      title="修改密码"
      left-text="返回"
      right-text="Mine"
      left-arrow
      @click-left="onClickLeft"
      @click-right="onClickRight"
    />
     <van-form @submit="onSubmit">
      <van-field
        v-model="oldPassword"
        name="oldPassword"
        label="旧密码"
        placeholder="请填写旧密码"
        :rules="[{ required: true, message: '请填写旧密码' }]"
      />
      <van-field
        v-model="password"
        name="password"
        label="新密码"
        placeholder="请填写新密码"
        :rules="[{ required: true, message: '请填写新密码' }]"
      />
      <van-field
        v-model="againpassword"
        name="againpassword"
        label="确认新密码"
        placeholder="请确认新密码"
        :rules="[{ required: true, message: '请确认新密码' }]"
      />
      <div style="margin: 16px">
        <van-button round block type="info" native-type="submit"
          >提交</van-button
        >
      </div>
    </van-form>
    </div>
</template>
<script>
export default{
    data() {
        return {
      oldPassword: "",
      password: "",
      againpassword: "",
        }
    },
    methods:{
         onClickLeft() {
      this.$router.go(-1);
    },
    onClickRight() {
      this.$router.push("Mine");
    },
    async onSubmit(val) {
      if (this.password === this.againpassword) {
        let res = await setuser(val);
        console.log(res);
        if (res.code == "success") {
          Toast.success(res.message);
          setTimeout(() => {
            this.$router.replace({
              name: "Login",
            });
          }, 500);
          this.$router.push("login");
        } else {
          Toast.fail(res.message);
        }
      } else {
        Toast("密码必须保持一致");
      }
    },
    }
}

</script>